# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libxslt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.29
pkgrel=2
pkgdesc="XML stylesheet transformation library (mingw-w64)"
arch=('any')
url="http://xmlsoft.org/XSLT/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libxml2" "${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'staticlibs')
install=${_realname}-${CARCH}.install
source=("http://xmlsoft.org/sources/${_realname}-${pkgver}.tar.gz"
        "libxslt-1.1.26-w64.patch"
        "libxslt-1.1.27-disable_static_modules.patch"
        "libxslt-1.1.28-win32-shared.patch"
        "libxslt.m4-libxslt-1.1.26.patch"
        '0002-python-linking-on.mingw.patch'
        '0003-fix-concurrent-directory-creation.all.patch'
        '0004-add-missing-include-for-python.all.patch'
        '0006-no-undefined-tests.patch'
        '0007-use-mingw-C99-compatible-functions-{v}snprintf.patch')
sha256sums=('b5976e3857837e7617b29f2249ebb5eeac34e249208d31f1fbf7a6ba7a4090ce'
            '887d7f22b2af770340d8f5b29bb490504d1ca904e289f03f9800f08f2b36e9ac'
            'e62f27315f2a25db3b6bfe5695d885998aeb3ad87cce6aebbd035c404fe8d378'
            '9f453d112f5170eb6aa504c41649fbcc6dc5e93e5cf678ab576e4609346ce8b2'
            'c02cd8437064db0921c08e63245c403dad12410d2997715aa7aa36600bfaa895'
            '2090ec6269e8e8b68a36922fca24f334872b702d81be8c9436fd9b25f506fc42'
            'fc23bd3c9e62a28cb1c020cebc83ca7532a5a7a21c2e4748b72d13ac7716a851'
            '1da234751e2bd337a0991a0f90272bbf83b6cbd8945208825fa3d9dd580020e6'
            'dec2cd6cabb8c4b80aa76a182ca23606582a94f2d1ec060ae9f2c9db90fe9fe0'
            '06e99e9c48fedd23fa9be704f227c437356aac14dc402a4ddf73b888d849cdd3')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/libxslt-1.1.26-w64.patch"
  patch -p1 -i "${srcdir}/libxslt-1.1.27-disable_static_modules.patch"
  patch -p1 -i "${srcdir}/libxslt-1.1.28-win32-shared.patch"
  patch -p1 -i "${srcdir}/libxslt.m4-libxslt-1.1.26.patch"

  patch -p1 -i "${srcdir}/0002-python-linking-on.mingw.patch"
  patch -p1 -i "${srcdir}/0003-fix-concurrent-directory-creation.all.patch"
  patch -p1 -i "${srcdir}/0004-add-missing-include-for-python.all.patch"
  patch -p1 -i "${srcdir}/0006-no-undefined-tests.patch"
  patch -p1 -i "${srcdir}/0007-use-mingw-C99-compatible-functions-{v}snprintf.patch"

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"
 ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --with-crypto \
    --with-plugins \
    --with-libxml-prefix=${MINGW_PREFIX} \
    --with-python=${MINGW_PREFIX}/bin/python2

  # Hack for mingw python
  local PREFIX_DEPS=$(cygpath -am ${MINGW_PREFIX})
  find . -type f -name "Makefile" -exec sed -i "s|${PREFIX_DEPS}|${MINGW_PREFIX}|g" {} \;
  CC=/mingw64/bin/gcc make
}

package() {
  export MSYS2_ARG_CONV_EXCL="-//OASIS"
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}

